<template>
    <div>
        <div :style="customStyle" class="whiteSpace">{{formatter(localValue, inData)}}</div>
    </div>
</template>

<script>
import BaseComp from "./baseComp";

export default {
    name: "commonText",
    extends: BaseComp,
    model: {
        prop: 'value',
        event: 'textChange'
    },
    props: {
        //传入当前列值
        value: {
            type: [String, Array, Object, Number]
        },
        //自定义样式
        customStyle: {
            type: Object,
            default: () => {
                return {};
            }
        },
        //当前列表头配置信息
        tableHeader: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    watch: {
        value: {
            handler(val){
                if (val){
                    this.localValue = val;
                }
            },
            deep: true,
            immediate: true
        }
    },
    data(){
        return{
            localValue: '',
        }
    },
    created() {
    },
    methods: {
        formatter(value, row){
            if (this.tableHeader.formatter && typeof this.tableHeader.formatter == 'function'){
                return this.tableHeader.formatter(value, row);
            }else {
                return value;
            }
        }
    },
    mounted() {
    }
}
</script>

<style scoped>
.whiteSpace{
    white-space: pre;
}
</style>
